<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id="mui-title">党组织列表</h1>
		</header>
		<div class="mui-content">
			<ul id="test" class="mui-table-view">
			</ul>
			<div class="mui-content-padded" style="text-align: center;">
				<ul id="pagination" class="mui-pagination mui-pagination-lg"></ul>
			</div>
		</div>
		<input type="hidden" id="pageNum" />
	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/util.js"></script>

	<script>
		mui.init({
			swipeBack: true //启用右滑关闭功能, 
		});
		
		
		(function($) {
			var showPageTotal=10;
			//设置全局beforeSend
			$.ajaxSettings.beforeSend = function(xhr, setting) {
				//beforeSend演示,也可在$.ajax({beforeSend:function(){}})中设置单个Ajax的beforeSend
				console.log('beforeSend:::' + JSON.stringify(setting));
			};
			//设置全局complete
			$.ajaxSettings.complete = function(xhr, status) {
				console.log('complete:::' + status);
			}
		
			
		
			//加载当前页数据
			showData("1",showPageTotal);
			
			function showData(pageNum,pageSizes){
			  	//从服务器获取数据
			  	var wv=plus.webview.currentWebview();//获取当前窗口的WebviewObject对象
			  	//业务数据获取完毕，并已插入当前页面DOM；
			  	//注意：若为ajax请求，则需将如下代码放在处理完ajax响应数据之后；
			  	//通过event.detail可获得传递过来的参数内容
				var dzzCode = wv.dzzCode;
				var groupName=wv.groupName;
				//发送请求事件
				//发送数据
				var data = {
					pageNum: pageNum,
					pageSizes: pageSizes,
					dzzCode: dzzCode,
				};
				mui.ajax({
					url: getDzzList,
					type: "get",
					data: data,
					async: true,
					dataType: "json",
					headers: {
						accept: "application/json;charset=UTF-8"
					},
					success: function(data) {
						data = eval(data);
						
						var temp_pagination = '';
						if(data.pageNum==1){
							temp_pagination+='<li class="mui-previous mui-disabled"><a href="#">«</a></li>';
						}else{
							temp_pagination+='<li class="mui-previous"><a href="#">«</a></li>';
						}						
						var pageList=mathPages(data.pageNum,data.pageCount)						
						for(var i=0;i<pageList.length;i++){
							if(pageList[i]==data.pageNum){
								temp_pagination+='<li class="mui-page mui-active"><a href="#">'+pageList[i]+'</a></li>';
							}else{
								temp_pagination+='<li class="mui-page"><a href="#">'+pageList[i]+'</a></li>';
							}
						}
					
						if(data.pageNum==data.pageCount){
							temp_pagination+='<li class="mui-next mui-disabled"><a href="#">»</a></li>';
						}else{
							temp_pagination+='<li class="mui-next"><a href="#">»</a></li>';
						}
						
						document.getElementById("pagination").innerHTML = temp_pagination;
						
						var temp = '';
						mui.each(data.data, function(unit, value) {
							temp += '<li class="mui-table-view-cell" data-groupName="'+value.groupName+'" data-groupId="' + value.groupId + '">' +
								'<a class="mui-navigate-right"><span class="mui-badge mui-badge-danger">' + value.dzzRyCount +
								'</span>' + value.groupName + '</a></li>';

						});
						document.getElementById("test").innerHTML = temp;
						document.getElementById("mui-title").innerHTML = groupName;
						document.getElementById("pageNum").value=data.pageNum;						
					}
				})
			  	mui.plusReady(function(){
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			  });
			}
			
			mui(".mui-pagination").on('tap', '.mui-page', function() {
				var pagetNum= this.innerText;
				showData(pagetNum,showPageTotal);
			})
			
			mui(".mui-pagination").on('tap', '.mui-previous', function() {
				showData(--(document.getElementById("pageNum").value),showPageTotal);
			})
			
			mui(".mui-pagination").on('tap', '.mui-next', function() {
				showData(++(document.getElementById("pageNum").value),showPageTotal);
			})
			
		
			mui(".mui-table-view").on('tap', '.mui-table-view-cell', function() {
				//获取id
				var groupId = this.getAttribute("data-groupId");
				var groupName = this.getAttribute("data-groupName");
				//打开新闻详情
				mui.openWindow({					
					url: 'data-dyUserList.html',
					extras:{
				      groupId:groupId,
				      groupName:groupName,
				   },
				   createNew:false
				});
			})
			
		})(mui);
	</script>
</html>